package com.sunyard.client2.ui;

import javax.swing.JPanel;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import com.sunyard.client.SunEcmClientApi;
import com.sunyard.client.bean.ClientBatchBean;
import com.sunyard.client2.ConnectionFactory;
import com.sunyard.client2.conf.ConfUtil;
import com.sunyard.util.DateUtil;

public class Check extends JPanel {
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;

	/**
	 * Create the panel.
	 */
	public Check() {
		setLayout(null);

		JButton btnNewButton = new JButton("检出");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					SunEcmClientApi clientApi = ConnectionFactory.getConnection();
					ClientBatchBean clientBatchBean = new ClientBatchBean();
					clientBatchBean.setModelCode(textField_4.getText());
					clientBatchBean.setUser(ConfUtil.getString("userName", ""));
					clientBatchBean.setPassWord(ConfUtil.getString("passWord", ""));
					clientBatchBean.getIndex_Object().addCustomMap(textField_2.getText(), textField_3.getText());
					clientBatchBean.getIndex_Object().setContentID(textField.getText());
					String resultMsg = clientApi.checkOut(clientBatchBean, ConfUtil.getString("groupName", ""));
					ResultMessageBox.getInstance().showMessage(resultMsg);
				} catch (Exception e1) {
					ResultMessageBox.getInstance().showMessage(e1.getMessage());
				}

			}
		});
		btnNewButton.setBounds(113, 203, 93, 23);
		add(btnNewButton);

		JButton btnNewButton_1 = new JButton("检入");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				try {
					SunEcmClientApi clientApi = ConnectionFactory.getConnection();
					ClientBatchBean clientBatchBean = new ClientBatchBean();
					clientBatchBean.setModelCode(textField_4.getText());
					clientBatchBean.setUser(ConfUtil.getString("userName", ""));
					clientBatchBean.setPassWord(ConfUtil.getString("passWord", ""));
					clientBatchBean.getIndex_Object().addCustomMap(textField_2.getText(), textField_3.getText());
					clientBatchBean.getIndex_Object().setContentID(textField.getText());
					clientBatchBean.setCheckToken(textField_1.getText());
					String resultMsg = clientApi.checkIn(clientBatchBean, ConfUtil.getString("groupName", ""));
					ResultMessageBox.getInstance().showMessage(resultMsg);
				} catch (Exception e1) {
					ResultMessageBox.getInstance().showMessage(e1.getMessage());
				}

			}
		});
		btnNewButton_1.setBounds(270, 203, 93, 23);
		add(btnNewButton_1);

		textField = new JTextField();
		textField.setBounds(113, 51, 389, 21);
		add(textField);
		textField.setColumns(10);

		textField_1 = new JTextField();
		textField_1.setBounds(113, 142, 389, 21);
		add(textField_1);
		textField_1.setColumns(10);

		JLabel lblNewLabel = new JLabel("批次编号：");
		lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel.setBounds(27, 54, 76, 15);
		add(lblNewLabel);

		JLabel lblNewLabel_1 = new JLabel("检出值：");
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_1.setBounds(27, 145, 76, 15);
		add(lblNewLabel_1);

		textField_2 = new JTextField();
		textField_2.setBounds(113, 96, 140, 21);
		add(textField_2);
		textField_2.setText(ConfUtil.getString("STARTCOLUMN", ""));
		textField_2.setColumns(10);

		JLabel lblNewLabel_2 = new JLabel("时间字段：");
		lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_2.setBounds(27, 99, 76, 15);
		add(lblNewLabel_2);

		JLabel label = new JLabel("业务时间：");
		label.setHorizontalAlignment(SwingConstants.RIGHT);
		label.setBounds(276, 99, 76, 15);
		add(label);

		textField_3 = new JTextField();
		textField_3.setColumns(10);
		textField_3.setText(ConfUtil.getString("STARTDATE", DateUtil.get8bitDateStr()));
		textField_3.setBounds(362, 96, 140, 21);
		add(textField_3);

		JLabel label_1 = new JLabel("模型：");
		label_1.setHorizontalAlignment(SwingConstants.RIGHT);
		label_1.setBounds(27, 10, 76, 15);
		add(label_1);

		textField_4 = new JTextField();
		textField_4.setColumns(10);
		textField_4.setBounds(113, 7, 389, 21);
		textField_4.setText(ConfUtil.getString("modelCode", ""));
		add(textField_4);

	}
}
